﻿using System.Collections;
using JetBrains.Annotations;
using KinonekoSoftware.CodariaDB.Documents.DataParts;
using KinonekoSoftware.CodariaDB.Documents.DataParts.Country;
using KinonekoSoftware.CodariaDB.Documents.DataParts.Story;
using KinonekoSoftware.Expressions.Core;
using KinonekoSoftware.Extensions.Collections;

namespace KinonekoSoftware.CodariaDB.IO
{
    public sealed class DataPartPictureFinder : ResourceFinder
    {
        public override void GetResources(ICollection<Resource> collection, IRepository repository)
        {
            var database = repository.Get<DataPart>(CollectionNames.DataPartDB);
            foreach (var part in database.FindAll())
            {
                if (part is Part_Detail)
                {
                    FindDetailResource(collection, part);
                }
                else if (part is Part_Story)
                {
                    FindStoryResource(collection, part);
                }
            }

        }

        private static void FindDetailResource(ICollection<Resource> collection, DataPart part)
        {

            // if (part is Part_Detail detail)
            // {
            //     foreach (var picture in detail.Pictures)
            //     {
            //         var id = picture.Id;
            //
            //         var thumbnail = new Resource
            //         {
            //             ImageID = string.Format(_File.ThumbnailIDPattern, id),
            //             Type    = ResourceType.Image,
            //             Usage   = true,
            //         };
            //
            //         var origin = new Resource
            //         {
            //             ImageID = id,
            //             Type    = ResourceType.Image,
            //             Usage   = true,
            //         };
            //
            //         collection.Add(thumbnail);
            //         collection.Add(origin);
            //     }
            //
            // }
        }
        
        
        private static void FindStoryResource(ICollection<Resource> collection, DataPart part)
        {

            if (part is Part_Story story)
            {
                //foreach (var storyboard in story.Storyboards)
                //{
                //    foreach (var block in storyboard.Blocks.OfType<IXCorePicture>())
                //    {
                        
                //        var id = block.Source;

                //        var thumbnail = new Resource
                //        {
                //            ImageID = string.Format(_File.ThumbnailIDPattern, id),
                //            Type    = ResourceType.Image,
                //            Usage   = true,
                //        };

                //        var origin = new Resource
                //        {
                //            ImageID = id,
                //            Type    = ResourceType.Image,
                //            Usage   = true,
                //        };

                //        collection.Add(thumbnail);
                //        collection.Add(origin);
                //    }
                //}

            }
        }
    }
}